home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / Add-Ons / MicroPhone / Open Mike™ / Open Mike™ 003 / Mike's Folder / DP Tutorial Pt.3 < prev    next >
Encoding:
Text File  |  1993-03-01  |  5.4 KB  |  85 lines  |  [TEXT/ttxt]

  1. DP Tutorial Pt.3
  2. ================
  3. Copyright © 1993 by Celestin Company
  4. All rights reserved.
  5.  
  6. No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage and retrieval system, without permission in writing from the publisher. However, you are permitted to make copies of this work, printed or otherwise, as long as said copies are for your personal use only.
  7.  
  8. Introduction
  9. ------------
  10. This time, we'll look at list boxes, how to figure out what item has been selected, how to change an item, add and remove items, and how to change an entire list. This part of the tutorial assumes that you went through the last two parts, or at least have a working knowledge of MicroPhone scripting and ResEdit.
  11.  
  12. List Boxes
  13. ----------
  14. List boxes are like any other item in a dialog, such as buttons and static text. However, when you go into ResEdit, you'll notice that there is no option for creating a list box. Instead, you use the useritem control, which looks like a gray box (make sure that the useritem is enabled by clicking on the appropriate checkbox in ResEdit). Take a look at the following script:
  15.  
  16.   Remark "--- 1 ---"
  17.   Set Variable * d0 from Expression "'List'"
  18.   Set Variable * d from Expression "MPDialogerPro(d0)"
  19.  
  20. DialogerPro does not know that the useritem you put into your dialog is a list box, so if you bring up the dialog without doing anything else, you'll see a rectangle instead of a list. DialogerPro draws a rectangle as a default when it spots a useritem in the dialog. To test this, run the script called "1" in this settings document.
  21.  
  22. So, how do we tell DialogerPro that we want it to treat the useritem as a list box? Look at this script:
  23.  
  24.   Remark "--- 2 ---"
  25.   Set Variable * d0 from Expression "'List'"
  26.   Set Variable * d4 from Expression "'4◊userList'"
  27.   Set Variable * d from Expression "MPDialogerPro(d0,d4)"
  28.  
  29. One of the parameters we pass to DialogerPro corresponds to item number 4 in the dialog (the useritem). We are giving DialogerPro the instruction to treat the useritem as a list box, hence the command userList. Run script "2" to see this in action. You should see an empty list, complete with scrollbar.
  30.  
  31. The following script will actually put some default items into the list:
  32.  
  33.   Remark "--- 3 ---"
  34.   Set Variable * d0 from Expression "'List'"
  35.   Set Variable * d4 from Expression "'4◊userList^MApple^MBanana^MCherry'"
  36.   Set Variable * d from Expression "MPDialogerPro(d0,d4)"
  37.  
  38. Hit Handler
  39. -----------
  40. Let's add a bit more complexity to the dialog by creating a hit handler. Now, whenever the dialog receives a hit, the hit handler will get executed. See the following scripts:
  41.  
  42.   Remark "--- 4 ---"
  43.   Set Variable * d0 from Expression "'List^Mon List Handler 4'"
  44.   Set Variable * d4 from Expression "'4◊userList^MApple^MBanana^MCherry'"
  45.   Set Variable * d from Expression "MPDialogerPro(d0,d4)"
  46.  
  47.   Remark "--- List Handler 4 ---"
  48.   If Expression "itemHit = '1'"
  49.     Alert * OK "'You clicked the OK button'"
  50.   Else If Expression "itemHit = '2'"
  51.     Alert * OK "'You clicked the Cancel button'"
  52.   Else If Expression "itemHit = '3'"
  53.     Alert * OK "'You clicked the Other button'"
  54.   Else If Expression "itemHit = '4'"
  55.     Beep
  56.   End If
  57.  
  58. This hit handler really doesn't do us much good. It tells us what we've clicked on, but otherwise, it doesn't do much. Let's create another hit handler that will show us which item in the list we selected:
  59.  
  60.   Remark "--- 5 ---"
  61.   Set Variable * d0 from Expression "'List^Mon List Handler 5'"
  62.   Set Variable * d4 from Expression "'4◊userList^MApple^MBanana^MCherry'"
  63.   Set Variable * d from Expression "MPDialogerPro(d0,d4)"
  64.  
  65.   Remark "--- List Handler 5 ---"
  66.   If Expression "itemHit = '1'"
  67.     Alert * OK "'You clicked the OK button'"
  68.   Else If Expression "itemHit = '2'"
  69.     Alert * OK "'You clicked the Cancel button'"
  70.   Else If Expression "itemHit = '3'"
  71.     Alert * OK "'You clicked the Other button'"
  72.   Else If Expression "itemHit = '4'"
  73.     Do XCMD * MPChangerPro "dialog,'5◊' & MPContentsPro(dialog,'4','Long')"
  74.   End If
  75.  
  76. Now, whenever you choose something in the list, you'll see it appear above the list. Try it by running script "5". Here, we introduce the use of MPChangerPro, which is an XCMD that allows you to make changes to a dialog that is already displayed. Here, we tell it to change item number 5 to display the contents of the selection in item number 4. Also new here is MPContentsPro, which returns the contents of the specified item in the dialog. The syntax is:
  77.  
  78.   MPContentsPro(dialogPointer,itemNumber,optional parameter)
  79.  
  80. where dialogPointer refers to the dialog whose contents we wish to inspect. Usually, just pass the variable "dialog" which will point to the current DialogerPro-generated dialog on the screen. ItemNumber refers to the number of the item in the dialog. The optional parameter can be 'Short', 'Long', or 'All'. To see what happens when you use the optional parameter of 'Short', try script "6".
  81.  
  82. Going Further
  83. -------------
  84. DialogerPro is very powerful, and its capabilities can be overwhelming. However, with a little patience, you too can master it. The best way to learn it is from example. Take a look at the scripts that drive all of the examples in Open Mike. Many use DialogerPro dialogs. By printing the scripts and studying them, you'll see what's possible and how to harness the power under MicroPhone's hood. Good luck with your adventures!
  85.